/********************************************************************************
 * BrowseItemsAction.java
 *
 * Created by Jigar Mistry
 * Last modified Date: Oct 1, 2008 9:52:03 AM by Jigar Mistry
 * Version : 0.1
 * Copyright (c) 2008 - 2009 cyberThink Infotech Pvt. Ltd., All rights reserved.
 ********************************************************************************/
package com.printeverywhere.action;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.interceptor.ServletRequestAware;
import org.w3c.dom.ls.LSException;

import com.opensymphony.xwork2.ActionContext;
import com.printeverywhere.delegator.CommonFunctionDelegator;
import com.printeverywhere.dto.GeneralCategories;
import com.printeverywhere.util.SearchCriteria;

public class BrowseItemsAction extends FrontBaseSupport implements ServletRequestAware {

	/**  */
	private static final long serialVersionUID = 1L;

	private HttpServletRequest request;

	private final boolean categories = true;

	private List<GeneralCategories> listGeneralCategories = new ArrayList<GeneralCategories>();

	public List<GeneralCategories> getListGeneralCategories() {
		return listGeneralCategories;
	}

	public void setListGeneralCategories(
			List<GeneralCategories> listGeneralCategories) {
		this.listGeneralCategories = listGeneralCategories;
	}

	public boolean isCategories() {
		return categories;
	}

	public BrowseItemsAction() {
		super(true, false);
		setCategoryDisplay(true);
	}

	public String execute() {
		if(ActionContext.getContext().getSession().get("securedPageParams") != null) {
			ActionContext.getContext().setParameters((Map) ActionContext.getContext().getSession().get("securedPageParams"));
			ActionContext.getContext().getSession().remove("securedPageParams");
		}

		SearchCriteria searchCriteria = new SearchCriteria();
		searchCriteria.setAttribute("generalCategories.categoryId", Integer.parseInt(this.request.getParameter("cid")));
		searchCriteria.setAttribute("active", Boolean.TRUE);
		this.listGeneralCategories = (List<GeneralCategories>) CommonFunctionDelegator.getObjectBySearchCriteria(searchCriteria, GeneralCategories.class);

		return SUCCESS;
	}

	public void setServletRequest(HttpServletRequest request) {
		this.request = request;
	}
}
